# 批量修改文件名
import os

filePath = './JVM笔记'
toPath = 'new'


def reNameFileName(path):
    if os.path.isfile(path):
        name = path
        cur = open(path, encoding='utf-8', mode='r+')
        basename = name[:name.rfind("/")]
        name = basename[basename.rfind("/"):] + '.md'
        # to = open("new" + name, encoding='utf-8', mode='a+')
        readline = cur.readline()
        while not readline and readline.strip() != '':
            print(readline)
            # to.write(readline)
            # to.flush()
    else:
        listdir = os.listdir(path)
        for item in listdir:
            reNameFileName(path + '/' + item)


reNameFileName(filePath)
